package com.ysm.freestyle.utils

import android.content.Context
import android.widget.Toast


object ToastUtil {
    private var toast: Toast? = null

    /**
     * 显示短时间 Toast 消息
     *
     * @param context 上下文
     * @param message 消息内容
     */
    fun showShortToast(context: Context?, message: String?) {
        if (toast == null) {
            toast = Toast.makeText(context, message, Toast.LENGTH_SHORT)
        } else {
            toast!!.setText(message)
            toast!!.duration = Toast.LENGTH_SHORT
        }
        toast!!.show()
    }

    /**
     * 显示长时间 Toast 消息
     *
     * @param context 上下文
     * @param message 消息内容
     */
    fun showLongToast(context: Context?, message: String?) {
        if (toast == null) {
            toast = Toast.makeText(context, message, Toast.LENGTH_LONG)
        } else {
            toast!!.setText(message)
            toast!!.duration = Toast.LENGTH_LONG
        }
        toast!!.show()
    }

    /**
     * 取消当前的 Toast
     */
    fun cancelToast() {
        if (toast != null) {
            toast!!.cancel()
        }
    }
}